﻿


/*  函数名：  返回时间 
*  说明：    格式化返回时间
*  参数：    yyyy 年份  MM 月份 dd 日期 hh 小时 mm 分钟 ss秒钟
*  返回值：
*  使用： new Date().format("yyyy年MM月dd日 hh:mm:ss")
************************************************************/
Date.prototype.format = function(format) {
    var o = {     //author:   meizz   
        "M+": this.getMonth() + 1,   //month   
        "d+": this.getDate(),         //day   
        "h+": this.getHours(),       //hour   
        "m+": this.getMinutes(),   //minute   
        "s+": this.getSeconds(),   //second   
        "q+": Math.floor((this.getMonth() + 3) / 3),     //quarter   
        "S": this.getMilliseconds()   //millisecond   
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
          (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
              RegExp.$1.length == 1 ? o[k] :
                  ("00" + o[k]).substr(("" + o[k]).length));
    return format;
};

//---------------------------------topic
function deltopic(btn) {
    // do nothing
}


// 专题选择对话框
// 2008-10-25 by linjie
function choosetopic(btn) {
    // do nothing
}
/***********************************************************
*  函数名：  MainFormJS() 
*
*  说明：    执行初始化功能,加载各界面元素
*
*  参数：    无
*
*  返回值：  无
*  
*  使用： MainFormJS()
************************************************************/

function MainFormJS() {
    //定义空白图标s.gif的路径
    Ext.BLANK_IMAGE_URL = 'Ext/s.gif';
    setTimeout(function() {
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({ remove: true });
    }, 500);

    // Set the session
    Ext.Ajax.request({
        url: 'sys/createSession.aspx',
        success: function(result, request) {
            //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
        },
        failure: function(result, request) {
            Ext.MessageBox.alert('Failed', 'Data return from the server: ' + result.responseText);
        }
    });

    //----------------------------------------------------
    // 禁用菜单和子菜单
    // 参数： menuObject  菜单对象 disable: bool 启用或者禁用
    //----------------------------------------------------
    function DisableAllMenu(menuObj, disable) {
        if (menuObj.items != null) {

            var menuItemCount = menuObj.items.getCount();
            if (menuItemCount > 0) {
                for (i = 0; i < menuItemCount; i++) {
                    var item = menuObj.items.itemAt(i);
                    DisableAllMenu(item, disable);
                }
            }
        }
        else {
            if (disable == true) {
                menuObj.disable();
            }
            else {
                menuObj.enable();
            }
        }
    }


    // Description: 选择专题
    // Parameter:   btn 菜单按钮对象
    // Creater:     王霜
    function chooseTopicForm(btn) {
        var count = tabMainContent.items.getCount() - 1;

        while (count >= 0) {
            tabMainContent.remove(tabMainContent.getComponent(count), true);
            count--;
        }
        choosetopic(btn);
    }

    // Description: 显示菜单对应的页面
    // Parameter:   btn    菜单按钮对象
    // Creater:     王霜
    function showPage(btn) {
        if (btn.getId() == 'CreateTopic') {
            // Clear all the tabs
            var count = tabMainContent.items.getCount() - 1;
            while (count >= 0) {
                tabMainContent.remove(tabMainContent.getComponent(count), true);
                count--;
            }
            // 王霜新函数
            NewTopic(btn);
            //JS/Processing/CreateTopic.js
            //ProcessCreateTopic();
            /*
            不要使用IFrame，使用函数。
            tabMainContent.add({
            id: 'CreateTopic',
            title: '首页',
            closable: true,
            html: '<iframe id="rightFrame" src="Processing/CreateTopic.aspx" width="100%" height="100%" scrolling="no"  frameborder="none" allowtransparency="true" >'
            })
            tabMainContent.activate('CreateTopic');*/
        }
        else {
            Ext.Ajax.request({
                url: 'sys/CheckSession.aspx',
                success: function(response, options) {
                    var responseArray = Ext.util.JSON.decode(response.responseText);
                    returnValue = responseArray.success;
                    if (responseArray.success == true) {
                        // 菜单ID
                        var menuID = btn.getId();
                        // 菜单内容
                        var menuText = btn.getEl().dom.lastChild.nodeValue;
                        var src;
                        switch (menuID) {
                            case 'Statistic': src = '../Modules/AIPC/Statistic.aspx'; break;
                            case 'IPCTrend': src = '../Modules/AIPC/IPCTrend.aspx'; break;
                            // 中国专项：专利类型分析   
                            case 'menuChineseType':
                                ChineseTypeAnalysis(menu5.items.itemAt(0));
                                break;
                            // 原产区域分布   
                            case 'menuOriginalAreaAnalysis':
                                ChineseOriginalAreaAnalysis(menu5.items.itemAt(1));
                                break;
                            // 专利趋势分析   
                            case 'menuChinaPatentTimeTrend':
                                ChinesePatentTimeTrend(menu5.items.itemAt(2));
                                break;
                            //专利申请人数量分析   
                            case 'menuChinaApplicantPatentCountAnalysis':
                                ChineseApplicantPatentCountAnalysis(menu5.items.itemAt(3).menu.items.itemAt(0));
                                break;
                            //申请人专利趋势   
                            case 'menuChinaApplicantPatentTrendAnalysis':
                                ChineseApplicantPatentTrendAnalysis(menu5.items.itemAt(3).menu.items.itemAt(1));
                                break;
                            case 'AreaChinese': src = '../Modules/AChina/areaChinese.aspx'; break;
                            case 'AreaInternaitonal': src = '../Modules/AChina/areaInternational.aspx'; break;
                            case 'AreaDetail': src = '../Modules/AChina/areaDetail.aspx'; break;

                            //case '专题建立':src='../Processing/CreateTopic.aspx';break;           
                            case 'ApplyTrend': src = '../Modules/AApplicant/ApplyTrend.aspx'; break; //申报趋势分析
                            case 'ApptPtDist': src = '../Modules/AApplicant/ApptPtDist.aspx'; break; //申请人专利分布


                            case 'localArea': src = '../Modules/AChina/localArea.aspx'; break; //申请人专利趋势
                            default: break;
                        }
                    }
                    else {

                        Ext.Msg.alert('！警告', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择专题！&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
                    }
                },
                failure: function(response, options) {
                    alert('Get Session.aspx failed');
                }
            });
        }
    }

    {  // 菜单
        var menu1 = new Ext.menu.Menu();

        menu1.add(
	    { text: "专利质量指标",
	        menu: {
	            items: [{ text: "专利批准率" },
	                    { text: "专利覆盖国家范围" },
	                    { text: "专利覆盖技术范围" },
	                    { text: "专利引用频率" },
	                    { text: "专利批准率" }
	          ]
	        }
	    },

        //菜单中添加分割线 '-'
        //'-',                            
	    {text: "专利影响力",
	    menu: {
	        items: [{ text: "当前影响力CII" },
	                    { text: "技术实力TS"}]
	    }
	},
	    { text: "技术关联度",
	        menu: {
	            items: [{ text: "专利引证" },
	                    { text: "交叉分类"}]
	        }
	    },
	    { text: "同族专利数量"
	    }
	);


        var menu2 = new Ext.menu.Menu();
        menu2.add(
	    { text: "专利区域分布",
	        menu: {
	            items: [{ text: "专利原产区域分布" },
	                    { text: "专利申请区域分布"}]
	        }
	    },
	    { text: "区域专利趋势",
	        menu: {
	            items: [{ text: "原产区域专利趋势" },
	                    { text: "申请区域专利趋势"}]
	        }
	    },
	    { text: "区域申请人分布",
	        menu: {
	            items: [{ text: "原产区域申请人分布" },
	                    { text: "申请区域申请人分布"}]
	        }
	    },
	    { text: "区域申请人趋势",
	        menu: {
	            items: [{ text: "原产区域申请人趋势" },
	                    { text: "申请区域申请人趋势"}]
	        }
	    },
	    { text: "区域技术构成",
	        menu: {
	            items: [{ text: "原产区域技术构成" },
	                    { text: "申请区域技术构成"}]
	        }
	    },
	    { text: "区域技术趋势",
	        menu: {
	            items: [{ text: "原产区域技术趋势" },
	                    { text: "申请区域技术趋势"}]
	        }
	    }
	);

        var menu3 = new Ext.menu.Menu();
        menu3.add(
	    { text: "申请人专利统计" },
	    { text: "申报趋势分析", id: 'ApplyTrend', handler: showPage },
	    { text: "申请人专利分布", id: 'ApptPtDist', handler: showPage },
	    { text: "申请人技术构成" }
	);

        var menu4 = new Ext.menu.Menu();
        menu4.add(
	    { text: "专利分类统计", handler: showPage, id: "Statistic" },
	    { text: "专利分类趋势分析", id: "IPCTrend", handler: showPage },
	    { text: "专利分类区域分析",
	        menu: {
	            items: [{ text: "专利申请区域" },
	    { text: "专利原产区域"}]
	        }
	    },
	    { text: "专利分类申请人分析"
	    },
	    { text: "专利分类发明人分析"
	    }
	    );

        var menu5 = new Ext.menu.Menu({
            shadow: 'frame'
        });
        menu5.add(
	    {
	        text: "专利类型分析",
	        handler: showPage,
	        id: "menuChineseType",
	        disabled: true,
	        iconCls: 'icon-chart-pie'
	    },
	    { text: "专利原产区域分布",
	        iconCls: 'icon-chart-columns',
	        handler: showPage,
	        id: "menuOriginalAreaAnalysis"
	    },
	    { text: "专利趋势分析",
	        iconCls: 'icon-chart-curve',
	        handler: showPage, id: "menuChinaPatentTimeTrend"
	    },
	    { text: "申请人分析",
	        iconCls: 'icon-users',
	        id: "menuChineseApplicantAnalysis",
	        menu: {
	            items: [{ text: "申请人专利数量",
	                iconCls: 'icon-chart-columns',
	                handler: showPage, id: "menuChinaApplicantPatentCountAnalysis"
	            },
	    { text: "申请人专利趋势",
	        iconCls: 'icon-chart-curve',
	        handler: showPage, id: "menuChinaApplicantPatentTrendAnalysis"
	    }
	    ]
	        }
	    },
	    { text: "技术生命周期",
	        iconCls: 'icon-tech-life'
	    },
	    { text: "权利要求分布",
	        iconCls: 'icon-right-request'
	    },
	    { text: "法律状态分析",
	        iconCls: 'icon-law'
	    }
	    );
        function ChangeCSS(menuItem) {
            var id = menuItem.getId();
            var name;
            switch (id) {
                case 'css-default': name = ''; break;
                case 'css-olive': name = 'xtheme-olive.css'; break;
                case 'css-gray': name = 'xtheme-gray.css'; break;
                case 'css-purple': name = 'xtheme-purple.css'; break;
                case 'css-slate': name = 'xtheme-slate.css'; break;
                case 'css-galdaka': name = 'xtheme-galdaka.css'; break;
                case 'css-darkgray': name = 'xtheme-darkgray.css'; break;
                case 'css-black': name = 'xtheme-black.css'; break;
            }
            var linkTags = document.getElementsByTagName("link");
            linkTags[linkTags.length - 1].href = "Ext/resources/css/" + name;

        }
        var menu6 = new Ext.menu.Menu();
        menu6.add(
	    {
	        text: "区域代码管理",
	        menu: {
	            items: [{
	                text: "国家代码管理"
	            }, {
	                text: "国内省市代码管理"
}]
	            }
	        },
	    { text: "IPC管理" },
	    { text: "专利清理", handler: deltopic },
	    { text: "标引管理",
	        menu: {
	            items: [
	    { text: "标引项设置" },
	    { text: "批量标引" },
	    { text: "标引合并" },
	    { text: "标引拆分" }
	    ]
	        }
	    },
	    { text: "职员管理" },
	    { text: "选择皮肤",
	        menu: {
	            items: [

	            { text: "默认", id: 'css-default',
	                checked: true,
	                group: 'theme',
	                checkHandler: ChangeCSS
	            },
	    { text: "浅绿", id: 'css-olive', checked: false,
	        group: 'theme',
	        checkHandler: ChangeCSS
	    },
	    { text: "银色", id: 'css-gray', checked: false,
	        group: 'theme',
	        checkHandler: ChangeCSS
	    },
	    { text: "紫色", id: 'css-purple', checked: false,
	        group: 'theme',
	        checkHandler: ChangeCSS},
	       
	    { text: "黑色", id: 'css-black', checked: false,
	        group: 'theme',
	         checkHandler: ChangeCSS
	        },
	        { text: "深灰", id: 'css-darkgray', checked: false,
	        group: 'theme',
	         checkHandler: ChangeCSS
	        },
	        
	        { text: "深蓝", id: 'css-slate', checked: false,
	        group: 'theme',
	        checkHandler: ChangeCSS
	        }
	         ]
	        }
	         
	    }
	    );

        var menu7 = new Ext.menu.Menu();
        menu7.add(
	    { text: "专题选择",
	        iconCls: 'icon-choose-topic',
	        handler: chooseTopicForm
	    }, {
	        text: "专题建立",
	        iconCls: 'icon-create-topic',
	        handler: showPage,
	        id: "CreateTopic"
	    }, {
	        text: "自动标引"
	    }, {
	        text: "手工标引"
	    }, {
	        text: "专利信息修正"
	    }, {
	        text: "申请人合并"
	    }, {
	        text: "发明人合并"
	    });

        var menu9 = new Ext.menu.Menu();
        menu9.add({ text: new Date().getDate() });

        var ta = new Ext.Toolbar();
        ta.render("panelToolbar");


        /**
        *添加菜单
        */
        ta.add({ text: "专利水平分析",
        disabled: true,
            iconCls: 'icon-chart-line',
            menu: menu1
        });
        ta.addSeparator();
        ta.add({ text: "专利区域分析",
        disabled: true,
            iconCls: 'icon-chart-curve',
            menu: menu2
        });
        ta.addSeparator();
        ta.add({ text: "申请人分析",
            disabled:true,
            iconCls: 'icon-users',
            menu: menu3
        });
        ta.addSeparator();
        ta.add({ text: "专利分类分析",
        disabled: true,
            iconCls: 'icon-chart',
            menu: menu4
        });
        ta.addSeparator();
        ta.add({ text: "中国专项分析",
        disabled: true,
            iconCls: 'icon-cn',
            menu: menu5, autocomplete: 'off'
        });
        ta.addSeparator();
        ta.add({ text: "专题管理",
            iconCls: 'icon-topic',
            menu: menu7
        });
        ta.addSeparator();
        ta.add({ text: "系统维护",
            iconCls: 'icon-system-manage',
            menu: menu6
        });
        /*
        DisableAllMenu(menu1, true);
        DisableAllMenu(menu2, true);
        DisableAllMenu(menu3, true);
        DisableAllMenu(menu4, true);
        DisableAllMenu(menu5, true);*/
    }

    //------------------------------- 页面布局 --------------------------------	

    /**
    * 页头
    */
    var top = new Ext.BoxComponent({
        region: "north",
        el: "panelTop",
        margins: "0 0 0 0",
        border: false
    });

    // Tab标签，用来显示页面。
    var tabMainContent = new Ext.TabPanel({
        id: 'tab',
        border: false,
        bodyStyle: 'border:none',
        bodyBorder:false,
        layoutOnTabChange: true,
        margins: "0 0 0 0",
        region: 'center',
        activeItem: 0,
        bbar: new Ext.StatusBar({
            defaultText: '合肥工业大学计算机与信息学院 2009',
            id: 'basic-statusbar',
            border: false,
            items: ['登录用户：', ' HFUT', '-', '登录时间：', ' ', new Date().format("yyyy年MM月dd日 hh:mm:ss"), '   ']
        })
    });


    // Viewport 代表整个浏览器可以显示的屏幕大小，其中按东南西北中进行布局。
    var panelMain = new Ext.Viewport({
        layout: "border",
        items: [top, tabMainContent]
    });


    //-------------------------------Topic.js
    function choosetopic(btn) {
        var index;
        var topicName;
        function processResult(sign) {
            if (true) {
                if (sign == 'yes') {
                    if (index != null) {
                        Ext.Ajax.request({
                            url: 'Sys/DelTopic.aspx?topicID=' + index,

                            success: function(response, options) {
                                Ext.Msg.alert('状态', '删除成功！');

                                grid.getStore().reload();
                            }
                        });
                    }
                }
            }
        }
        var bodyMask = new Ext.LoadMask(Ext.getBody(), { msg: "请稍候..." });
        var grid = new Ext.grid.GridPanel({
            //id:'grid',                        
            border: false,
            width: 585,
            height: 395,
            loadMask: bodyMask,
            autoScroll: true,
            containerScroll: true,
            store: new Ext.data.Store({
                url: 'sys/getTopics.aspx',
                autoLoad: true,
                reader: new Ext.data.JsonReader({

                    id: 'p_topicID'
                }, [
							{ name: 'p_topicID', mapping: 'TopicID' },
							{ name: 'name', mapping: 'TopicName' }
						])
            }),
            cm: new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
				{ header: "专题编号", width: 80, sortable: true, dataIndex: 'p_topicID' },
				{ header: "专题名称", width: 505, sortable: true, dataIndex: 'name' }
            //{header: "", width: 50,  text:'删除'}
            //{text:'删除'}
			]),

            viewConfig: {
                forceFit: true
            },
            tbar: [{
                text: '专题名称:'
            }, {
                xtype: 'textfield',
                id: 'topicNameTextField',
                text: ' ',
                width: 200,
                disabled: true
            }, '-', new Ext.Button({
                id: 'ok-btn',
                text: '确定',
                handler: function() {
                    // index is stored before
                    if (index != null) {
                        ta.items.itemAt(0).enable();
                        ta.items.itemAt(2).enable();
                        ta.items.itemAt(4).enable();
                        ta.items.itemAt(6).enable();
                        ta.items.itemAt(8).enable();
                        
                        /*DisableAllMenu(menu1, false);
                        DisableAllMenu(menu2, false);
                        DisableAllMenu(menu3, false);
                        DisableAllMenu(menu4, false);*/
                        Ext.Ajax.request({
                            url: 'sys/CreateTopicIDSessionEx.aspx',
                            params: {
                                topicID: index
                            },
                            method: 'post',
                            success: function(response, options) {
                                //document.getElementById("topicName").innerHTML = "安徽省专利信息分析系统——" + topicName;
                                document.title = "安徽省专利信息分析系统——" + topicName;
                                var responseArray = Ext.util.JSON.decode(response.responseText);
                                returnValue = responseArray.success;
                                if (responseArray.success == true) {
                                    if (responseArray.isChinesePatent) {
                                        DisableAllMenu(menu5, false);
                                    }
                                    else {
                                        DisableAllMenu(menu5, true);
                                    }
                                }
                                else {
                                    Ext.Msg.alert('失败', '选择专题出错！');
                                    alert(response.responseText);
                                }
                            }
                        });
                    }
                    win.hide();
                },
                scope: this
            }
				), ' ',
				new Ext.Button({
				    text: '删除',
				    handler: function() {
				        Ext.Msg.confirm('确认', '确认删除吗？', processResult);

				    }
				}),
				new Ext.Button({
				    text: '关闭',
				    handler: function() {
				        win.hide();

				    }
				})

				]
        });

        grid.on('rowclick', function(grid, t) {

            var selectedRow = grid.getSelectionModel().getSelected();
            index = selectedRow.get("p_topicID")
            topicName = selectedRow.get("name");
            var bar = grid.getTopToolbar();
            var con = grid.getTopToolbar().items.get(1);
            con.setValue(topicName);
        });
        var win = new Ext.Window({ title: '专题选择',
            width: 600,
            height: 430,
            plain: true,
            closeAction: 'hide',
            iconCls: 'icon-topic',
            items: grid
        });
        win.show(btn.getEl().dom);
    }

    //----------------------------------------------------
    // 添加Tab
    // menu   菜单对象， grid  panel对象， icon css的class
    // 该方法已废弃。原因：多了一层包装。
    //----------------------------------------------------
    GridMain = function(menu, grid, icon) {
        var tab = tabMainContent.getItem(menu.id);
        if (!tab) {
            var tab = tabMainContent.add({
                id: menu.id,
                iconCls: icon,
                width: 200,
                xtype: "panel",
                title: menu.getEl().dom.lastChild.nodeValue,
                closable: true,
                layout: "fit",
                items: [grid]
            });
        }
        tabMainContent.setActiveTab(tab);
    }
	//----------------------------------------------------
    // 添加Tab
    // menu   菜单对象， tab中要显示的对象， icon css的class
    //----------------------------------------------------
    GridMain2 = function(menu, itemPanel, icon) {
        var tab = tabMainContent.getItem(menu.id);
        if (!tab) {
            var tab = tabMainContent.add({
                id: menu.id,
                iconCls: icon,
                bodyStyle: 'border:none',
                bodyBorder:false,
                
                border: false,
                width: 200,
                xtype: "panel",
                title: menu.getEl().dom.lastChild.nodeValue,
                closable: true,
                layout: "border",
                items: itemPanel
            });
        }
        tabMainContent.setActiveTab(tab);
    }


}

// 开始执行
Ext.onReady(MainFormJS);
